package com.woniuxy.propertyjava.controller;

import com.woniuxy.propertyjava.entity.Lifeservice;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.LifeserviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class LifeserviceController {
    @Autowired
    LifeserviceService lifeserviceService;
    @PostMapping("/lifeservice/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Lifeservice>> getAllLifeservice(@PathVariable("pageIndex") int pageIndex,
                                                                   @PathVariable("pageSize") int pageSize,
                                                                   @RequestBody Lifeservice lifeservice){

        PageBean<Lifeservice> pageBean = lifeserviceService.getLifeserviceByPage(pageIndex, pageSize, lifeservice);
        return new ResponseResult<>(200,"ok",pageBean);
    }

    @PostMapping("/lifeservice")
    public ResponseResult<Lifeservice> addLifeservice(@RequestBody Lifeservice lifeservice){
        System.out.println("添加生活服务："+lifeservice);
        lifeserviceService.insertLifeservice(lifeservice);
        return new ResponseResult<>(200, "ok",null);
    }

    @PutMapping("/lifeservice")
    public ResponseResult<Lifeservice> modifyLifeservice(@RequestBody Lifeservice lifeservice){
        System.out.println("修改生活服务："+lifeservice);
        lifeserviceService.updateLifeservice(lifeservice);
        return new ResponseResult<>(200, "ok",null);
    }

    @DeleteMapping("/lifeservice/{serviceid}")
    public ResponseResult<Lifeservice> removeLifeservice(@PathVariable("serviceid") int serviceid){
        System.out.println("删除生活服务："+serviceid);
        lifeserviceService.deletLifeservice(serviceid);
        return new ResponseResult<>(200, "ok",null);
    }
}
